// 这是一个用于测试 Prettier 格式化效果的文件
type User = {
  name: string
  age: number
  email?: string
  isActive: boolean
}

function formatUserName(user: User): string {
  return user.name.toUpperCase() + (user.isActive ? ' (活跃)' : ' (非活跃)')
}

// 获取活跃用户
const getActiveUsers = (users: User[], minAge: number = 0): User[] =>
  users.filter(user => user.isActive && user.age >= minAge)

// 示例用户数据
const exampleUsers: User[] = [
  { name: '张三', age: 28, isActive: true },
  { name: '李四', age: 32, email: 'lisi@example.com', isActive: false },
  { name: '王五', age: 25, isActive: true }
]

// 使用示例用户数据
const activeUsers = getActiveUsers(exampleUsers, 25)
console.warn('活跃用户:', activeUsers)

class UserManager {
  private users: User[]

  constructor(initialUsers: User[]) {
    this.users = initialUsers
  }

  public addUser(user: User): void {
    if (this.users.some(u => u.email === user.email && user.email !== undefined)) {
      throw new Error('User with this email already exists')
    }
    this.users.push(user)
  }

  public getFormattedUserNames(): string[] {
    return this.users.map(user => formatUserName(user))
  }
}

export type { User }
export { formatUserName, getActiveUsers, UserManager }
